﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Input;
using LeapLibrary;
using Leap;

namespace TronLeapRacing
{
    class OptionsMenue
    {
        ContentManager Content;

        //Timerzeit
        const float TIMER = 2;

        Texture2D background;
        Texture2D currentZurueck;
        Texture2D cursor;
        Texture2D left;
        Texture2D right;
        Texture2D help;
        Texture2D helpSetting;

        Vector2 bgPosition = new Vector2(0, 0);
        Vector2 handPosition = Vector2.Zero;

        float timerZurueck = TIMER;

        Control control;
        //Game Infos
        Game1 g1ref;

        String arrowState = "left";

        public OptionsMenue(Game1 g1ref)
        {
            this.g1ref = g1ref;
        }

        public void LoadContent(ContentManager Content)
        {
            this.Content = Content;
            background = Content.Load<Texture2D>("Background/TronBackground");
            currentZurueck = Content.Load<Texture2D>("Button/TronZurueck");
            cursor = Content.Load<Texture2D>("Texturen/cursor");
            left = Content.Load<Texture2D>("Texturen/leftOptions");
            right = Content.Load<Texture2D>("Texturen/rightOptions");
            help = Content.Load<Texture2D>("Texturen/hilfe");
            helpSetting = Content.Load<Texture2D>("Texturen/An");
        }

        public void Update(Control control, GameTime gameTime)
        {
            
            this.control = control;
            handPosition = control.getPosition();

            if ( control.optionsSwipe()!= "null" && control.getPosition().Y > 220 && control.getPosition().Y < 300)
                arrowState = control.optionsSwipe();

            // überprüfe ob cursor über Textur ist
            if (control.getPosition().X > -165 && control.getPosition().X < 115 && control.getPosition().Y > 100 && control.getPosition().Y < 180)
                {
                    timerZurueck -= (float)gameTime.ElapsedGameTime.TotalSeconds;
                    if (timerZurueck < 2)
                        currentZurueck = Content.Load<Texture2D>("Hover/tronZurueckHover1");
                    if (timerZurueck < 1.8)
                        currentZurueck = Content.Load<Texture2D>("Hover/tronZurueckHover2");
                    if (timerZurueck < 1.6)
                        currentZurueck = Content.Load<Texture2D>("Hover/tronZurueckHover3");
                    if (timerZurueck < 1.4)
                        currentZurueck = Content.Load<Texture2D>("Hover/tronZurueckHover4");
                    if (timerZurueck < 1.2)
                        currentZurueck = Content.Load<Texture2D>("Hover/tronZurueckHover5");
                    if (timerZurueck < 1)
                        currentZurueck = Content.Load<Texture2D>("Hover/tronZurueckHover6");
                    if (timerZurueck < 0.8)
                        currentZurueck = Content.Load<Texture2D>("Hover/tronZurueckHover7");
                    if (timerZurueck < 0.6)
                        currentZurueck = Content.Load<Texture2D>("Hover/tronZurueckHover8");
                    if (timerZurueck < 0.4)
                        currentZurueck = Content.Load<Texture2D>("Hover/tronZurueckHover9");
                    if (timerZurueck < 0.2)
                        currentZurueck = Content.Load<Texture2D>("Hover/tronZurueckHover10");
                    if (timerZurueck < 0)
                    {
                        timerZurueck = 5;
                        g1ref.setGamestate("intro");
                    }
                }
                else
                {
                    timerZurueck = TIMER;
                    currentZurueck = Content.Load<Texture2D>("Button/TronZurueck");
                }
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Begin();
            spriteBatch.Draw(background, bgPosition, Color.White);
            spriteBatch.Draw(help, new Vector2(250, 240), Color.White);

            if (arrowState.Equals("left"))
            {
                helpSetting = Content.Load<Texture2D>("Texturen/An");
                spriteBatch.Draw(right, new Vector2(650, 240), Color.White);
                spriteBatch.Draw(helpSetting, new Vector2(520, 240), Color.White);
                g1ref.setTutorialOn(true);
            }

            else
            {
                helpSetting = Content.Load<Texture2D>("Texturen/Aus");
                spriteBatch.Draw(left, new Vector2(450, 240), Color.White);
                spriteBatch.Draw(helpSetting, new Vector2(510, 240), Color.White);
                g1ref.setTutorialOn(false);
            }

            spriteBatch.Draw(currentZurueck, new Vector2(330, 370), Color.White);
            spriteBatch.Draw(cursor, new Vector2(handPosition.X + 470, -1 * (handPosition.Y - 500)), Color.White);
            spriteBatch.End();
        }
    }
}
